<template>
	<view>

	</view>
</template>

<script>
	import {
		$get,
	} from "@/utils/request.js"
	import methods from '@/utils/methods.js'

	export default {
		data() {
			return {
				infoList: {
					invitationCode: ''
				}
			};
		},
		onLoad(option) {
			const userToken = uni.getStorageSync('token')
			if (!userToken) {
				methods.login()
			}
			const {
				invitationCode
			} = option;
			if (invitationCode) {
				this.verification(invitationCode);
			} else {
				this.showErrorAndRedirect('邀请码失效');
			}
		},
		methods: {
			// 显示错误信息并跳转到首页
			showErrorAndRedirect(message) {
				uni.showToast({
					icon: "error",
					title: message
				})
				setTimeout(() => {
					uni.switchTab({
						url: '/pages/index/index'
					})
				}, 2000)
			},
			verification(invitationCode) {
				$get(`/system/staff/getJobNumber?jobNumber=${invitationCode}`)
					.then(res => {
						if (res.code === 200) {
							const newinfoList = {
								intervieweeJobNumber: res.data.jobNumber,
								intervieweeName: res.data.nickName,
								intervieweeDepartName: res.data.deptName,
								intervieweeDepart: res.data.deptId,
								firmName: res.data.firmName,
							};
							const paramsStr = JSON.stringify(newinfoList);
							uni.navigateTo({
								url: `/pages/register/register?paramsStr=${encodeURIComponent(paramsStr)}`
							})
						} else {
							const message = res.msg || '未查询到相关信息';
							this.showErrorAndRedirect(message);
						}
					})
					.catch(err => {
						this.showErrorAndRedirect('查询失败');
					});
			}
		}
	}
</script>

<style lang="scss">

</style>